package com.example.tests;

import com.example.utils.SortedListOf;
import org.testng.annotations.Test;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

public class AddressCreationTestSet extends TestBase{

    @Test(dataProvider = "addressesFromXMLFile")
    public void testValidAddressCreation(AddressData addressData) throws Exception {

        //save old state from DB
        SortedListOf<AddressData> oldAddressList
                = new SortedListOf<AddressData>(applicationManager.getModel().getAddressList());

        //actions
        applicationManager.getAddressHelper().createAddress(addressData);

        //save new state from GUI
        SortedListOf<AddressData> newAddressList
                = applicationManager.getAddressHelper()
                    .getGuiAddressList();

        //compare states
        oldAddressList = oldAddressList.withAdded(addressData.withNoNulls());
        assertThat(newAddressList, equalTo(oldAddressList));
    }
}
